package offer.tree;

/**
 * @author DengYuan2
 * @create 2021-02-27 19:02
 */
public class n_28 {
    public static void main(String[] args) {
        n_28 n = new n_28();
        TreeNode t1 = new TreeNode(8);
        TreeNode t2 = new TreeNode(6);
        TreeNode t3 = new TreeNode(9);
        TreeNode t4 = new TreeNode(5);
        TreeNode t5 = new TreeNode(7);
        TreeNode t6 = new TreeNode(7);
        TreeNode t7 = new TreeNode(5);
        t1.left=t2;
        t1.right=t3;
        t2.left=t4;
        t2.right=t5;
        t3.left=t6;
        t3.right=t7;
        boolean res = n.isSymmetrical(t1);
        System.out.println(res);
    }

    /**
     *
     * @param pRoot
     * @return
     */
    boolean isSymmetrical(TreeNode pRoot) {
        if (pRoot==null){
            return true;
        }
        return helper(pRoot.left,pRoot.right);
    }

    boolean helper(TreeNode t1,TreeNode t2){
        if (t1==null&&t2==null){
            return true;
        }
        if (t1==null || t2==null){
            return false;
        }
        if (t1.val==t2.val){
            return helper(t1.left,t2.right)&&helper(t1.right,t2.left);
        }
        return false;
    }
}













